/*--------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------*/
// prichtextbox.hpp - Rich Text box class definition.
//
// Author: Kalpesh Balar
//
// Copyright (c) 1997-2000 Swell Software
//              All Rights Reserved.
//
// Unauthorized redistribution of this source code, in whole or part,
// without the express written permission of Swell Software
// is strictly prohibited.
//
// Notes:
//
/*--------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------*/


#ifndef _PEGRICHTEXTBOX_
#define _PEGRICHTEXTBOX_

#if defined(PEG_RICH_TEXT_SUPPORT)

#ifndef PEG_TB_WHITESPACE
#define PEG_TB_WHITESPACE 2     // white space to leave on borders
#endif
/*--------------------------------------------------------------------------*/
#define MAX_PARSE_STRING_LEN 1000
#define MAX_FILENAME_LEN    30
//Rich Font style
const PEGUBYTE RF_NORMAL   = 0x0000;
const PEGUBYTE RF_BOLD     = 0x0001;
const PEGUBYTE RF_ITALIC   = 0x0002;
const PEGUBYTE RF_UNDERLINE= 0x0004;

/* RichTextNode structure to hold rich text properties  */
struct RichTextNode
{
    RichTextNode *pNext;
    PEGCHAR *Text;
    PegPoint Put;
    PEGCOLOR Color;
    PEGUINT FontId;
    PEGUBYTE Align;
    PEGBOOL UnderLine;
};

/* Color table for RTF */
struct RtfColorTable
{
    PEGCOLOR ColorId;
    RtfColorTable *pNext;
};

typedef enum {PropBold, PropItalic, PropUl, PropNotUl, PropCf, PropFs,
    PropJustC, PropJustR, PropJustL, PropRed, PropBlue, PropGreen, PropCTable
    } ACTION;

typedef enum {kwdChar, kwdProp, kwdSkip} KWDTYPE;

struct KeyWordInfo
{
    PEGCT *RtfKeyWord;
    PEGINT Action;
    KWDTYPE Type;
    PEGBOOL PassDef;
};

/*--------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------*/
class PegRichTextBox : public PegWindow
{
    public:
        PegRichTextBox(const PegRect &Rect, PEGUSHORT Id = 0,
                   PEGULONG Style = FF_RECESSED|EF_WRAP|TJ_LEFT);

        virtual ~PegRichTextBox();

        virtual void Draw(const PegRect &Invalid);
        virtual void GetVScrollInfo(PegScrollInfo *Put);
        virtual PEGINT Message(const PegMessage &Mesg);
        virtual void Resize(const PegRect &Size);
        virtual void RtfParser(PEGCT *pFileName);
        virtual void RtfParser(PEGCHAR *pRtfBuff);
        virtual void SetNumFont(PEGUSHORT number);
        virtual void SetRichFont(PEGUINT FontId, PEGUINT FontIndex);


    protected:
        virtual void AddColorToRTFColorTable(void);
        virtual void AddDrawObjectNode(void);
        virtual void ApplyPropChange(PEGINT Action, PEGINT param);
        void ClipToClient(const PegRect &Invalid);
        virtual void DrawAllRichText(const PegRect &Invalid);
        void EndClipToClient(void);
        virtual const PEGCHAR *FindNextLine(const PEGCHAR *pText, PEGINT MaxWidth,
                                PEGUINT FontId, PEGINT Dir = 1);
        virtual PEGCOLOR GetColor(PEGUBYTE Red, PEGUBYTE Green, PEGUBYTE Blue);
        PEGCOLOR virtual GetColorFromRTFColorTable(PEGUBYTE index);
        virtual void ParseChar(PEGINT Action);
        virtual void ParseRtfKeyWord(void);
        virtual void TranslateKeyword(PEGCT *ketword, PEGINT param,
                        PEGBOOL fParam);

        PEGCT mParseText[MAX_PARSE_STRING_LEN];
        PEGCT mFileName[MAX_FILENAME_LEN];
        PegFile *mpFile;
        PEGCHAR *mpRtfBuff;
        PEGCHAR mRtfBuff[MAX_PARSE_STRING_LEN];
        RichTextNode *mpDrawHome;
        RichTextNode *mpDrawEnd;
        RtfColorTable *mpColorHome;
        PEGINT *mpRichFontTable;

        PegPoint mPut;
        PEGINT mWhiteSpace;
        PEGINT mWidestLine;
        PEGINT mTotalLines;
        PEGINT mVisible;
        PEGUSHORT mNumFont;
        PEGUBYTE mRed;
        PEGUBYTE mBlue;
        PEGUBYTE mGreen;
        PEGUBYTE mColorIndex;
        PEGUBYTE mBIUstyle;
        PEGUBYTE mFontSize;
        PEGUBYTE mAlignment;
        PEGUBYTE mVertShift;
        PEGBOOL mFileMode;
};

#endif  // PEG_RICH_TEXT_SUPPORT

#endif


